<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-07-29 10:10
 *
 * Version: 2.0
 */

namespace App\Modules\Member\Criterias;


use Flower\Core\Repository\Contracts\RepositoryInterface;
use Flower\Core\Repository\Criterias\BaseCriterias;

class GetWxCoinListCriteria extends BaseCriterias
{
	private $params;
	public function __construct($params)
	{
		$this->params = $params;
	}

	public function apply($model, RepositoryInterface $repository)
	{
		$select = implode([
			'hx_member_coin.id',
			'hx_member_coin.coin as consumption',
			'hx_order.order_no as orderNo',
			'hx_order_item.service_name as serviceName',
			'hx_member_coin.created_at',
		],',');
		return $model->selectRaw($select)
			->leftJoin('order','member_coin.link_id','order.id')
			->leftJoin('order_item','order.id','order_item.order_id')
			->where('member_coin.member_id','=',$this->params)
			->orderBy('id','desc');
	}
}